package com.chen.controller;

import com.chen.service.IBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
@RequestMapping("/app")
@Api(value = "分布式应用程序")
public class BusinessController {

    @Resource
    private IBusinessService businessService;

    @PostMapping("/transferA2B")
    @ApiOperation(value = "模拟从A账户向B账户转账")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accountId1",value = "A账户",example = "1"),
            @ApiImplicitParam(name = "accountId2",value = "B账户",example = "2"),
            @ApiImplicitParam(name = "amount",value = "转账金额",example = "3")
    })
    public void transferA2B(int accountId1, int accountId2, BigDecimal amount){
        businessService.transferA2B(accountId1,accountId2,amount);
    }

    @PostMapping("/transferA2BWithException")
    @ApiOperation(value = "模拟从A账户向B账户转账")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accountId1",value = "A账户",example = "1"),
            @ApiImplicitParam(name = "accountId2",value = "B账户",example = "2"),
            @ApiImplicitParam(name = "amount",value = "转账金额",example = "3")
    })
    public void transferA2BWithException(int accountId1, int accountId2, BigDecimal amount){
        businessService.transferA2BWithException(accountId1,accountId2,amount);
    }
}
